import time
from selenium import webdriver
from selenium.webdriver.common.by import By

driver = webdriver.Chrome()
driver.get('https://www.so.com')
driver.maximize_window()

driver.find_element(By.ID, 'input').send_keys('python')
driver.find_element(By.ID, 'search-button').click()

# 到最底层
js1 = 'window.scrollTo(0,document.body.scrollHeight)'
driver.execute_script(js1)
time.sleep(3)

#  到最顶层
js2 = 'window.scrollTo(0,0)'
driver.execute_script(js2)
time.sleep(3)

# 回到最底层 options(包含3个属性)  smooth:平缓滚动 instant:瞬间滚动
js3 = 'window.scrollTo({left:0,top:document.body.scrollHeight,behavior:"smooth"})'
driver.execute_script(js3)
time.sleep(3)

# 聚焦(滚动到给定元素的位置)
target = driver.find_element(By.PARTIAL_LINK_TEXT, '我要自学网')

driver.execute_script('arguments[0].scrollIntoView();', target)
time.sleep(3)

driver.quit()
